package com.gxa.medical.controller;

import com.gxa.medical.service.UserDetailsService;
import com.gxa.medical.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/userDetails")
public class UserDetailsController {
    @Autowired
    UserDetailsService userDetailsService;

    @PostMapping("/register")
    public Map<String, Object> insert(@RequestBody Map map, HttpServletRequest request) throws Exception {
        JsonResult jsonResult = new JsonResult();
        HttpSession session = request.getSession();
        Integer user_id = (Integer) session.getAttribute("user_id");
        map.put("user_id", user_id);
        if (map.get("sex").equals("1")) {
            map.put("sex", true);
        } else {
            map.put("sex", false);
        }
        Integer integer = userDetailsService.insertUserDetails(map);
        if (integer > 0) {
            jsonResult.setCode("1");
        } else {
            jsonResult.setCode("0");
        }
        return jsonResult.getResultMap();
    }
}
